from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer,Float
from sqlalchemy.orm import sessionmaker

#数据库连接
engine = create_engine("mysql+pymysql://root:root@localhost:3306/movierecommend", echo=True)
Base = declarative_base()
session = sessionmaker(bind=engine)()

# 数据库建表
#电影表
# class movie(Base):
#     __tablename__ = "movie"
#     movieid = Column(Integer, primary_key=True)
#     moviename = Column(String(255), default=None, nullable=False)
#     updateyear = Column(Integer, default=None, nullable=False)
#     rate = Column(Float,nullable=False)
#     heat = Column(Float,default=None,nullable=False)
#     description = Column(String(255), default=None, nullable=False)
#     post = Column(String(255), default=None, nullable=False)
#
# Base.metadata.create_all(engine)
# session.commit()  # 需要调用commit()方法提交事务。


# class movieLabel(Base):
#     __tablename__ = "movieLabel"
#     movieid = Column(Integer, primary_key=True)
#     labelid = Column(Integer, primary_key=True)
#
# Base.metadata.create_all(engine)
# session.commit()  # 需要调用commit()方法提交事务。

class label(Base):
    __tablename__ = "label"
    labelid = Column(Integer, primary_key=True)
    labelname = Column(String(255), default=None, nullable=False)


Base.metadata.create_all(engine)
session.commit()  # 需要调用commit()方法提交事务。